<!DOCTYPE html>
<html lang="en"><!-- InstanceBegin template="/Templates/MainTemplate.dwt" codeOutsideHTMLIsLocked="false" -->
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
<!-- #BeginEditable "doctitle" -->
<title>Jdon Framework Qucik start</title>  
<!-- #EndEditable -->
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
    <!-- Bootstrap core CSS -->
     <link rel="stylesheet" href="css/bootstrap.min.css">   

    <!-- Custom styles for this template -->
    <link href="css/starter-template.css" rel="stylesheet">

   <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
    <![endif]-->    
  </head>
<body>
 <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="index.html">Jdon Framework</a>
        </div>
        <div class="collapse navbar-collapse">
          <ul class="nav navbar-nav">
                <li class="active"><a href="index.html">Home</a></li>
               <li><a href="https://sourceforge.net/projects/jdon/files/">Download</a></li>
               <li><a href="doc.htm" >Document</a></li>
               <li><a href="quickconf.html">Qucik Start</a> </li>
               <li><a href="examples.html">Examples</a></li>
               <li ><a href="https://github.com/banq/jdonframework">Github</a></li>
               <li><a href="articles.html">Articles</a></li>
          </ul>
        </div><!--/.nav-collapse -->
      </div>
    </div>
    

    <div class="container">
     <div class="starter-template">     
    
 <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">  
  <tr>     
    <td bgcolor="#FFFFFF"  valign="top" align="left">

                  
				<!-- #BeginEditable "main" --> 
                  <h1 align="center"><strong>Quick Start </strong></h1>
                  <p align="center">&nbsp;</p>
                  <p align="left">Maven pom.xml</p>
                  <p align="left">&lt;dependency&gt;<br>
                    　　　　&lt;groupId&gt;org.jdon&lt;/groupId&gt;<br>
                    　　　　&lt;artifactId&gt;jdonframework&lt;/artifactId&gt;<br>
                    　　　　&lt;version&gt;6.8&lt;/version&gt;<br>
                    &lt;/dependency&gt; </p>
                  <p align="left">this quickStart's source code in <a href="https://github.com/banq/jdonframework/tree/master/src/test/java/com/jdon/sample/test/domain/simplecase" target="_blank">github</a></p>
                  <p align="left">&nbsp;</p>
                  <h3 align="left">1. keep domain model in-memory cache:</h3>
                  <p>There are two steps:</p>
                  <p>(1) annotate your aggregate root with @Model</p>
                  <div>
                    <div>@Model&#13;</div>
                    <div>public class MyModel {&#13;</div>
                    <div> &nbsp;&nbsp;&nbsp;private String Id;&#13;</div>
                    <div>&nbsp;&nbsp;&nbsp;private String name;&#13;</div>
                    <div>     ....&#13;</div>
                    <div>}&#13;</div>
                    <div></div>
                    <div></div>
                  </div>
                  <p>full code see <a href="https://github.com/banq/jdonframework/blob/master/src/test/java/com/jdon/sample/test/domain/simplecase/MyModel.java" target="_blank">MyModel.java</a></p>
                  <p>&nbsp;</p>
                  <p>(2) annotate your factory/repository of the aggregate root with @Introduce(“modelCache”) </p>
                  <p>&nbsp;</p>
                  <p>When a domain model object with @Model is fetch from repository, we need use @Introduce(“modelCache”) to mak the object live in memory.<br>
                  </p>
                  <p>@Introduce(“modelCache”) must be annotated in 
                    the interfaces that @Model objects are created or reconstructed  
                    , the interfaces is such as repository class. DDD think repository is the transfering betwing the database data and domain object.</p>
                  <p><strong>This step is very important for domain events</strong></p>
                  <p><img src="images/introducecache.png" width="416" height="208" alt="cachge"></p>
                  <p>full code: <a href="https://github.com/banq/jdonframework/blob/master/src/test/java/com/jdon/sample/test/domain/simplecase/repository/RepositoryImp.java" target="_blank">RepositoryImp.java</a></p>
                  <p>&nbsp;</p>
                  <h3>2.annotate a Producer class @Introduce(&quot;message&quot;)</h3>
                  <pre><div id="LC61">@Introduce("message")</div><div id="LC62">public class MyModelDomainEvent {</div><div id="LC63"><br></div><div id="LC64">        @Send("MyModel.findName")</div><div id="LC65">        public DomainMessage asyncFindName(FindNameEvent findNameEvent) {</div><div id="LC66">                return new DomainMessage(findNameEvent);</div><div id="LC67">        }</div><div id="LC68"><br></div><div id="LC69">        @Send("saveMyModel")</div><div id="LC70">        public DomainMessage save(MyModelCreatedEvent myModelCreatedEvent) {</div><div id="LC71">                return new DomainMessage(myModelCreatedEvent);</div><div id="LC72">        }</div><div id="LC73"><br></div><div id="LC74">}</div>
                  </pre>
                  <p>in this class, there are Producer's fire/emit method with  @Send(&quot;mytopic&quot;); such as @Send("MyModel.findName").</p>
                <p>@Introduce(“message”)：&quot;message&quot;  is the om.jdon.domain.message.MessageInterceptor configured in aspect.xml
                It means introducing a MessageInterceptor for this class.</p>
                  <p>@ Send(&quot;mytopic&quot;): &quot;mytopic&quot; is your topic name that equals to the &quot;mytopic&quot; in @Consumer(&quot;mytopic&quot;);<br>
                  In this method, you must marshal your data into a DomainMessag that can be unmarshal in consumers.</p>
                  <p>full code :<a href="https://github.com/banq/jdonframework/blob/master/src/test/java/com/jdon/sample/test/domain/simplecase/MyModelDomainEvent.java" target="_blank">MyModelDomainEvent.java</a><br>
                  </p>
                  <p><br>
                  </p>
                  <h3>3. annotate a Consumer class with @Consumer(&quot;mytopic&quot;); or @OnEvent</h3>
                  <p>in above step, <a href="https://github.com/banq/jdonframework/blob/master/src/test/java/com/jdon/sample/test/domain/simplecase/MyModelDomainEvent.java" target="_blank">MyModelDomainEvent.java</a> have two topic: &quot;MyModel.findName&quot; and &quot;saveMyModel&quot;, we must implement two consumer classed to listen/observe these topic.</p>
                  <p>first topic consumer class:</p>
                  <pre><div id="LC22">@Consumer("MyModel.findName")</div><div id="LC23">public class FindNameListener implements DomainEventHandler {</div><div id="LC24"><br></div><div id="LC25">        public void onEvent(EventDisruptor event, boolean endOfBatch) throws Exception {</div><div id="LC26">                FindNameEvent findNameEvent = (FindNameEvent) event.getDomainMessage().getEventSource();</div><div id="LC27">                System.out.println("Asynchronous eventMessage=" + findNameEvent.getId());</div><div id="LC28">                event.getDomainMessage().setEventResult("Asynchronous eventMessage=" + findNameEvent.getId());</div><div id="LC29">        }</div><div id="LC30">}</div>
                  </pre>
                  <p>&nbsp;</p>
                  <p>the class must annotate with Consumer, and implements interface com.jdon.domain.message.DomainEventHandler, and accomplish its method &quot;onEvent&quot;. in this method you can get the Event(value object, such as orderCreated ), here is FindNameEvent:</p>
                  <pre><div id="LC">public class FindNameEvent {</div><div id="LC2"><br></div><div id="LC3">        private final Long id;</div><div id="LC4"><br></div><div id="LC5">        public FindNameEvent(Long id) {</div><div id="LC6">                super();</div><div id="LC7">                this.id = id;</div><div id="LC8">        }</div><div id="LC9"><br></div><div id="LC31">        public Long getId() {</div><div id="LC32">                return id;</div><div id="LC33">        }</div><div id="LC34"><br></div><div id="LC35">}</div>
                  </pre>
                  <p>&nbsp;</p>
                  <p>but maybe you wonder where the &quot;FindNameEvent&quot; instance comes  from? in Procuder class,  the method &quot;asyncFindName&quot; returns a type DomainMessage, and the code is &quot;return new DomainMessage(findNameEvent)&quot;, yeah, the findNameEvent is input. in general, we should input a DomainEvents, such as &quot;new OrderCreated(xx,xx)&quot; , donot directly put entity instance.</p>
                  <p>&nbsp;</p>
                  <p>another consumer annotation is @OnEvent, it can annotate any class with @Component:</p>
                  <pre><div id="LC10">@Component("mymrepository")</div><div id="LC11">@Introduce("modelCache")</div><div id="LC12">public class RepositoryImp implements MyModelRepository {</div><div id="LC13"><br></div><div id="LC14">        @Around</div><div id="LC15">        public MyModel getModel(Long key) {</div><div id="LC16">                MyModel mym = new MyModel();</div><div id="LC17">                mym.setId(key);</div><div id="LC18">                return mym;</div><div id="LC19">        }</div><div id="LC20"><br></div><div id="LC36">        @OnEvent("saveMyModel")</div><div id="LC37">        public void save(MyModelCreatedEvent myModelCreatedEvent) {</div><div id="LC38">                System.out.print("\n No.2 @OnEvent:" + this.getClass().getName());</div><div id="LC39"><br></div><div id="LC40">        }</div><div id="LC41"><br></div><div id="LC21">}</div>
                  </pre>
                  <p>&nbsp;</p>
                  <p>the topic &quot;saveMyModel&quot; consumer is RepositoryImp, in this repository we just find the aggregate root &quot;MyModel&quot; instance, and we can save the model by &quot;save(MyModelCreatedEvent myModelCreatedEvent)&quot;, here method parameter MyModelCreatedEvent is from the producer's method return's object(DomainMessage). myModelCreatedEvent as event object is too recommended, in general, we transfer a domainevent such as new OrderSaved(), if you saving the domain events, you can replay them to get root entity's state, this is called Event Soucing.</p>
                  <p>&nbsp;</p>
                  <pre><div id="LC75">public class MyModelCreatedEvent {</div><div id="LC76"><br></div><div id="LC77">        private final Long id;</div><div id="LC78">        private final String name;</div><div id="LC79"><br></div><div id="LC80">        public MyModelCreatedEvent(Long id, String name) {</div><div id="LC81">                super();</div><div id="LC82">                this.id = id;</div><div id="LC83">                this.name = name;</div><div id="LC84">        }</div><div id="LC85"><br></div><div id="LC86">        public Long getId() {</div><div id="LC87">                return id;</div><div id="LC88">        }</div><div id="LC89"><br></div><div id="LC90">        public String getName() {</div><div id="LC91">                return name;</div><div id="LC92">        }</div><div id="LC93"><br></div><div id="LC94">}</div>
                  </pre>
                  <p>&nbsp;</p>
                <p>&nbsp;</p>
                  <h3>4. combine producer with root entity</h3>
                  <p>now we have a producer and two consumer,  we need introduce the producer into our aggregate root entity:</p>
                  <pre><div id="LC42">@Model</div><div id="LC43">public class MyModel {</div><div id="LC44"><br></div><div id="LC45">        private Long id;</div><div id="LC46">        private String name;</div><div id="LC47"><br></div><div id="LC48">        @Inject</div><div id="LC49">        private MyModelDomainEvent myModelDomainEvent;
</div>
                  </pre>
                  <pre><div id="LC50">        public String getName() {</div><div id="LC51">                if (this.name == null) {</div><div id="LC52">                        DomainMessage message = myModelDomainEvent.asyncFindName(new FindNameEvent(this.id));</div><div id="LC53">                        this.name = (String) message.getBlockEventResult();</div><div id="LC54">                }</div><div id="LC55">                return name;</div><div id="LC56">        }</div><div id="LC57"><br></div><div id="LC58">        public void save() {</div><div id="LC59">                myModelDomainEvent.save(new MyModelCreatedEvent(this.id, this.name));</div><div id="LC60">        }</div>
                  </pre>
                  <p>&nbsp;</p>
                  <p>&nbsp;</p>
                  <p>@Inject is used to inject any class instance into domain model, here we inject our procuder MyModelDomainEvent.</p>
                  <p>and in save() method, we invoke &quot;myModelDomainEvent.save(new MyModelCreatedEvent(..))&quot; to implement fire a domain event, such as new OrderSaved(); here,</p>
                  <p>getName() method send a lazy-load event.</p>
                  <p>&nbsp;</p>
                  <h3>5. Client</h3>
                  <p>all main steps finished.</p>
                <p>Service is a bounded context, and is a client for our aggregate:</p>
                <pre><div id="LC95">@Service("serviceSampleTwo")</div><div id="LC96">public class ServiceSampleTwo implements IServiceSampleTwo {</div><div id="LC97"><br></div><div id="LC98">        private MyModelRepository repository;</div><div id="LC99"></div><div id="LC100"><br></div><div id="LC101">        public ServiceSampleTwo(MyModelRepository repository) {</div><div id="LC102">                super();</div><div id="LC103">                this.repository = repository;</div><div id="LC104">                this.nameFinderContext = nameFinderContext;</div><div id="LC105">        }</div><div id="LC106"><br></div><div id="LC107">        public Object eventPointEntry() {</div><div id="LC108">                MyModel myModel = repository.getModel(new Long(100));</div><div id="LC109">                MyModel myModel2 = repository.getModel(new Long(100));</div><div id="LC110">                return myModel.sayHelloSynchronous() + " and " + myModel2.getName();</div><div id="LC111"><br></div><div id="LC112">        }</div>
                </pre>
                <pre><div id="LC113">         public void onEventTest() {</div><div id="LC114">                MyModel myModel = repository.getModel(new Long(100));</div><div id="LC115">                myModel.setName("new name");</div><div id="LC116">                myModel.save();</div><div id="LC117">        }</div>
                </pre>
                <p>&nbsp;</p>
                <p>Service's invoking :</p>
                <pre><div id="LC140">AppUtil appUtil = new AppUtil();</div><div id="LC141">IServiceSampleTwo serviceSample = (IServiceSampleTwo) appUtil.getService("serviceSampleTwo");</div><div id="LC142">String res = (String) serviceSample.eventPointEntry();</div><div id="LC143">System.out.print(res);</div><div id="LC144">Assert.assertEquals(res, "Synchronous sayHello and Asynchronous eventMessage=100");</div>
                </pre>
                <p>&nbsp;</p>
                <p>&nbsp;</p>
                  <p align="left">this quickStart's source code in <a href="https://github.com/banq/jdonframework/tree/master/src/test/java/com/jdon/sample/test/domain/simplecase" target="_blank">github</a></p>
                  <div>
                    <div>                    </div>
                    <div></div>
                  </div>
                  <p align="left">&nbsp;</p>
                  <p><BR>
                  </p>
                  <p>&nbsp;</p>
                   <!-- #EndEditable -->
                 
			  	
          </td>
		  <td width="340" valign="top"  bgcolor="#FFFFD7"> 
          <div class="adsensf" id="vgad336x280">
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- 页上左336 -->
<ins class="adsbygoogle"
     style="display:inline-block;width:336px;height:280px"
     data-ad-client="ca-pub-7573657117119544"
     data-ad-slot="6751585519"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- 页上左336 -->
<ins class="adsbygoogle"
     style="display:inline-block;width:336px;height:280px"
     data-ad-client="ca-pub-7573657117119544"
     data-ad-slot="6751585519"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>         
 </td>
  </tr>
</table>


<table width="100%" border="0" cellspacing="0" cellpadding="0" height="2" bgcolor="#000000"  align="center">
              <tr>
                <td></td>
              </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr><td height="20" bgcolor="#CAC9BB" align="center">
  
  </td>
</tr>
</table>
 </div>
</div><!-- /.container -->

<!-- InstanceBeginEditable name="EditRegion3" --><!-- InstanceEndEditable -->
        <script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
		<script src="js/bootstrap.min.js"></script>
<!-- AddThis Smart Layers BEGIN -->
<!-- Go to http://www.addthis.com/get/smart-layers to customize -->
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-52c4b79515624135"></script>
<script type="text/javascript">
  addthis.layers({
    'theme' : 'transparent',
    'share' : {
      'position' : 'left',
      'numPreferredServices' : 5
    },  
    'whatsnext' : {},  
    'recommended' : {} 
  });
</script>
<!-- AddThis Smart Layers END -->    
</body>
<!-- InstanceEnd --></html>
